/*
 * File Name:               XComponent.cs
 *
 * Description:             组件模式的组件类
 * Author:                  lisiyu
 * Create Date:             2016/09/14
 */

public abstract class IComponent<TOwner, TComponent, TContainer> 
    where TOwner : class
    where TComponent : IComponent<TOwner, TComponent, TContainer>
    where TContainer : XContainer<TOwner, TComponent, TContainer>, new()
{
    protected TOwner mOwner;
    protected TContainer mContainer;

    public void onSpawn(TOwner owner, TContainer container)
    {
        mOwner = owner;
        mContainer = container;
    }

    public void onRecycle()
    {
        mOwner = null;
        mContainer = null;
    }

    public abstract void onAdd(params object[] args);

    public abstract void onRemove();

    ///// <summary>
    ///// 暂时屏蔽掉组件之间的互相引用
    ///// 考虑到各种复杂的引用情况及先后顺序
    ///// 放到更上层也许是好的处理方案
    ///// </summary>
    ///// <typeparam name="K"></typeparam>
    ///// <returns></returns>
    //protected K getComponent<K>() where K : TComponent
    //{
    //    return mContainer.getComponent<K>();
    //}
}